﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AlexandriaPressPublisherBusinessLayer;
using AlexandriaPressUserBusinessLayer;

namespace AlexandriaPressWebsite.MasterPages
{
    public partial class WebForm4 : System.Web.UI.Page
    {
        protected void Page_Init(object sender, EventArgs e)
        {
            if (HttpContext.Current.User.Identity.Name != "")
            {
                UserBusinsessLayer business = new UserBusinsessLayer();
                string _UserType = business.getUserType(HttpContext.Current.User.Identity.Name);
                if (_UserType == "Type_ProofReader")
                {

                }
                else
                {
                    Response.Redirect("~/MasterPages/ErrorPage.aspx");
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        { 
            DraftsGridView.EmptyDataText = "There are currently no unassigned drafts.";
            DraftsGridView.DataSource = ProofreaderProcessManager.getAllDrafts();
            DraftsGridView.DataBind();     
        }

        protected void Timer1_Tick(object sender, EventArgs e)
        {
            DraftsGridView.DataBind(); 
        }

        protected void SubmitButton_Click(object sender, EventArgs e)
        { 
            string selectedValue = Request.Form["RadioButton"];
            if (selectedValue != null)
            {
                if (ProofreaderProcessManager.checkForUnassignedUser(Convert.ToInt32(Session["userID"])) == 0)
                {
                    Session.Add("draftForDownload", selectedValue);
                    Response.Redirect("~/MasterPages/ProofreaderPages/DownloadPage.aspx");
                }
                else
                {
                    Response.Redirect("~/MasterPages/ProofreaderPages/AssignedWorkValidationPage.aspx");
                }
            }
        }

        protected void DraftsGridView_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            DraftsGridView.PageIndex = e.NewPageIndex;
            DraftsGridView.DataSource = ProofreaderProcessManager.getAllDrafts();
            DraftsGridView.DataBind();  
        }

        protected void CancelButton_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/MasterPages/ProofreaderPages/ProofReaderConsole.aspx");
        }
    }
}
